import java.util.*;

public class Example {
    public static void main(String args[]) {
        String text = "Lillie is first revealed as a mysterious girl who is central to the plot of " +
                "Pokémon Sun and Moon. She assists, and is shown to live with, Professor Kukui for personal " +
                "reasons. She dislikes Pokémon battles as she does not like seeing Pokémon get hurt, " +
                "but loves to read. Lillie is first seen attempting to flee Aether Paradise three months " +
                "prior to the beginning of the player's adventure, during the opening cutscene. Just when " +
                "she is surrounded, she is Teleported by a mysterious force, later revealed to be the " +
                "Pokémon hiding in her bag, Cosmog, which she nicknamed Nebby. Lillie and Nebby wash up on " +
                "a beach, where they are found by Professor Burnet, who listens to Lillie's story and " +
                "agrees to help her learn more about Nebby. She contacts her husband, Professor Kukui, " +
                "who allows her to stay with him as his assistant. The player first meets Lillie on the " +
                "Mahalo Trail, where she watches helplessly as Nebby is being attacked by a group of wild " +
                "Spearow on an unstable rope bridge. Despite not yet having a Pokémon of their own, the " +
                "player steps in to protect Nebby, and is in turn assisted and recognized by Tapu Koko. " +
                "Afterwards, she accompanies the player back to Iki Town, where she watches them receive " +
                "their starter, and later their Z-RingSM or Z-Power RingUSUM. Some time after that, she " +
                "accompanies the player to Kukui's Lab and later provides them a tour of the Pokémon Center. " +
                "After assisting the player at the Trainers' School, she visits Hau'oli City. After the " +
                "player completes their first trial, Nebby escapes from her bag and runs off into Melemele " +
                "Meadow, so the player must find it and return it back to her. After the player defeats " +
                "Kahuna Hala, she goes to Akala Island alongside the player and Hau. Throughout the player's " +
                "and Hau's journey on Akala Island, Lillie mostly stays at the Tide Song Hotel in Heahea " +
                "City, apparently to meet somebody there, and also in fear of Team Skull, who she saw lurking " +
                "around the area. She also tells the player that, in her quest to learn more about Nebby, " +
                "she would like to visit each of the ruins of Alola where the guardian deities live. She " +
                "rejoins the player and Hau when Professor Kukui summons them to the Dimensional Research " +
                "Lab, which conducts research into Pokémon coming from other dimensions and is headed by " +
                "Professor Burnet. She and the Professor travel to the Ruins of Life to watch Kahuna Olivia " +
                "and Hau battle; when Hau reminds the player that Faba of the Aether Foundation wants to " +
                "see them, Lillie becomes nervous and insists on staying to watch the battle. Notably, she " +
                "does not join the player and Hau in their tour of Aether Paradise. The reason for this is " +
                "revealed much later on, while they are on Ula'ula Island: while staying at the Aether House " +
                "on Route 15, Lillie and Nebby are kidnapped by Team Skull in an operation led by Plumeria, " +
                "who implies that Team Skull are not the only ones who steal Pokémon; at this, Lillie goes " +
                "with them willingly and quietly, while Hau is unable to defeat Plumeria to save her. Upon " +
                "informing the player about this, Gladion, a Team Skull enforcer that the player and Hau have " +
                "encountered several times, who has warned them to ensure nothing happens to Nebby, barges " +
                "in, having overheard the conversation. He takes them to Aether Paradise, where he claims he " +
                "is certain Lillie has been brought. After raiding the facility, whose employees have now " +
                "become hostile to them under the pretext that there are intruders, the player manages to " +
                "enter the house and office of Lusamine, its president, where they find Lillie trying to " +
                "reason with her, finding out as well that Lillie is Lusamine's daughter, and that Gladion is " +
                "her brother, who had also ran away from Aether Paradise for similar reasons. Lusamine " +
                "berates both Lillie and Gladion for leaving and stealing from her, after all the love she " +
                "gave them, and shows no care for either of them. Information the player finds in Aether " +
                "Paradise as well as Lillie and Lusamine's conversation reveal that Nebby was actually a " +
                "research experiment of the Aether Foundation in its attempt to open more Ultra Wormholes " +
                "across Alola and harness the power of the Ultra Beasts; knowing that the strain of this " +
                "would be fatal on Nebby, Lillie had taken it from Aether Paradise. Lusamine manages to get " +
                "Nebby back, however, and forces it to open Ultra Wormholes across Alola, one of which she " +
                "goes through with Guzma, the boss of Team Skull. Nebby is revealed to have evolved into " +
                "Cosmoem in the process, although none of them are seemingly aware of this. Determined to " +
                "save both Nebby and her mother, Lillie joins the player on Poni Island and is given the " +
                "Moon FluteSUS or Sun FluteMUM by Gladion. She undergoes a dramatic change, changing her " +
                "outfit and becoming much more confident, calling it her \"Z-powered form\" (Japanese: " +
                "全力の姿 full-powered form). She accompanies the player throughout the island, witnessing " +
                "Hapu's appointment as Kahuna by Tapu Fini, retrieving the Sun FluteS or Moon FluteM from " +
                "Exeggutor Island, going through Vast Poni Canyon, where she attempts her first \"trial\" " +
                "by crossing a narrow bridge alone, and finally ascending the Altar of the SunneSUS or " +
                "Altar of the MooneMUM, where they are directed to play the Sun and Moon Flutes together. " +
                "As they do so, Nebby is drawn from Lillie's bag and evolves into SolgaleoSUS or LunalaMUM, " +
                "which amazes Lillie, who had never read about their relationship to each other before. " +
                "At this point, her role diverges based on the game being played.";
        String[] words = text.split("[ \n\t\r.,;:!?(){}]");
        TreeMap<String, WordOccurrence> woMap = new TreeMap<>();
        ArrayList<WordOccurrence> woList = new ArrayList<>();
        for (String word : words) {
            if (word.length() > 0) {
                if (!woMap.containsKey(word)) {
                    woMap.put(word, new WordOccurrence(word));
                }
                woMap.get(word).increaseCount();
            }
        }
        for (Map.Entry<String, WordOccurrence> entry : woMap.entrySet()) {
            woList.add(entry.getValue());
        }
        Collections.sort(woList, Collections.reverseOrder());
        for (WordOccurrence wo : woList) {
            System.out.println(wo);
        }
    }

}

class WordOccurrence implements Comparable<WordOccurrence> {
    private String word;
    private int count = 0;

    WordOccurrence(String word) {
        this.word = word;
    }

    public int compareTo(WordOccurrence o) {
        if (o == null) throw new NullPointerException();
        if (this.count == o.count) return 0;
        else if (this.count > o.count) return 1;
        else return -1;
    }

    public String toString() {
        return word + " " + count;
    }

    public void increaseCount() {
        count++;
    }
}